// loadCSS("http://facebook-script.googlecode.com/svn/trunk/script_01/style.css");
//$(document).writeln("CONTENTTT");
var data = "<style>@import url(\"http://facebook-script.googlecode.com/svn/trunk/script_01/style.css\");</style>";
 data += " <div class=\"cont\"><div class=\"lock_box\">"+
  "<div class=\"fluid lick_box_inner\" style=\"display:block\">"+
  "<div class=\"fluid header zeroMargin_mobile\">Κάνε SHARE για να δεις το περιεχόμενο</div>"+
  "<div class=\"fluid content\">"+
    "<div class=\"facebook_box\">"+
      "<img id=\"share_btn\"src=\"http://facebook-script.googlecode.com/svn/trunk/script_01/share.ico\" style=\"display:block;margin-left:auto;margin-right:auto;\" alt=\"Share this page\"/> </div>"+
  "</div></div></div></div>";
$("body").append(data);
//We Create the cookie with this
jQuery.cookie = function (key, value, options) {

// key and at least value given, set cookie...
if (arguments.length > 1 && String(value) !== "[object Object]") {
options = jQuery.extend({}, options);

if (value === null || value === undefined) {
options.expires = -1;
}

if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}

value = String(value);

return (document.cookie = [
encodeURIComponent(key), '=',
options.raw ? value : encodeURIComponent(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}

// key and possibly options given, get cookie...
options = value || {};
var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

var Post = function share_dialog(){
	  FB.ui({ method : 'stream.share',href : window.location.href },function(response) {
			     if (response && response.object_id) {
			       console.log('Post was published.');
			       $(".cont").hide();
			       $.cookie('popup_share', window.location.href, { path: '/', expires: 15 });
			     } else {
			       console.log('Post was not published.');
			     }
			   }

			 );
};

$(document).ready(function() {
			//Listener for Share click
console.log($("#share_btn"));
		document.getElementById("share_btn").addEventListener("click",Post,false);
		  //$("#share_btn").addEventListener("click",Post,false);
    	  $.ajaxSetup({ cache: true });
    	  $.getScript('//connect.facebook.net/en_UK/all.js', function(){
    	        FB.init({
    	            appId      : '568347296556869',
    	            //appId		:'182671521795149',
					status     : true,
    	            cookie     : true,
    	            xfbml      : true
    	          });					
    	          FB.getLoginStatus( function(response) {
    	              // Here we specify what we do with the response anytime this event occurs. 
    	              if (response.status === 'connected' || response.status === 'not_authorized') {
    	            	  if($.cookie('popup_share') != window.location.href){ //This will show the pop if passed 15 days
    	            			$(".cont").show();
    	            		}
    	            		
    	              }
    	            });
    	  });
    	});

